The use of object-oriented programming techniques can facilitate the development of complex computer programs. Programming languages that support object-oriented techniques have been developed. One such programming language is C++.
Two common characteristics of object-oriented programming languages are support for data encapsulation and data type inheritance. Data encapsulation refers to the binding of functions and data. Inheritance refers to the ability to declare a data type in terms of other data types.
In the C++ language, object-oriented techniques are supported through the use classes. A class is a user-defined type. A class declaration describes the data members and function members of the class. For example, the following declaration defines data members and function member of a class named CIRCLE. ##STR1## Variables x and y specify the center location of a circle and variable radius specifies the radius of the circle. These variables are referred to as data members of the class CIRCLE. The function draw is a user-defined function that draws the circle of the specified radius at the specified location. The function draw is referred to as a function member of class CIRCLE. The data members and function members of a class are bound together in that the function operates an instance of the class. An instance of a class is also called an object of the class.
In the syntax of C++, the following statement declares the objects a and b to be of type class CIRCLE. EQU CIRCLE a, b;
This declaration causes the allocation of memory for the objects a and b, such an allocation is called an instance of the class. The following statements assign data to the data members of objects a and b. EQU a.x=2; EQU a.y=2; EQU a.radius=1; EQU b.x=4; EQU b.y=5; EQU b.radius=2;
The following statements are used to draw the circles defined by objects a and b. EQU a.draw(); EQU b.draw();
A derived class is a class that inherits the characteristics--data members and function members--of its base classes. For example, the following derived class CIRCLE.sub.-- FILL inherits the characteristics of the base class CIRCLE. ##STR2## This declaration specifies that class CIRCLE.sub.-- FILL includes all the data and function members that are in class CIRCLE in addition to the those data and function members introduced in the declaration of class CIRCLE.sub.-- FILL, that is, data member pattern and function member fill. In this example, class CIRCLE.sub.-- FILL would have data members x, y, radius, and pattern and function members draw and fill. Class CIRCLE.sub.-- FILL is said to "inherit" the characteristics of class CIRCLE. A class that inherits the characteristics of another class is a derived class (e.g., CIRCLE.sub.-- FILL). A class that does not inherit the characteristics of another class is a primary class (e.g., CIRCLE). A class whose characteristics are inherited by another class is a base class (e.g., CIRCLE is a base class of CIRCLE.sub.-- FILL). A derived class may inherit the characteristics of several classes, that is, a derived class may have several base classes. This is referred to as multiple inheritance.
A derived class may specify that a base class is to be inherited virtually. Virtual inheritance of a base class means that only one instance of the virtual base class exists in the derived class. For example, the following is an example of a derived class with two non-virtual base classes. EQU class PATTERN: CIRCLE, CIRCLE{ . . . };
In this declaration class PATTERN inherits class CIRCLE twice non-virtually. There are two instances of class CIRCLE in class PATTERN.
The following is an example of a derived class with two virtual base classes. EQU class PATTERN: virtual CIRCLE, virtual CIRCLE{ . . . };
The derived class PATTERN inherits class CIRCLE twice virtually. Since the class CIRCLE is virtually inherited twice, there is only one object of class CIRCLE in the derived class PATTERN. This is the simplest use of virtual inheritance and is not particularly useful. One skilled in the art would appreciate virtual inheritance can be very useful when the class derivation is more complex.
A class may also specify whether its function members are to be virtually inherited. Declaring that a function member is virtual means that the function can be overridden by a function of the same name and type in a derived class. In the following example, the function draw is declared to be virtual in classes CIRCLE and CIRCLE.sub.-- FILL. ##STR3## Continuing with the example, the following statement declares object a to be of type class CIRCLE and object b to be of type class CIRCLE.sub.-- FILL. EQU CIRCLE a; EQU CIRCLE.sub.-- FILL b;
The following statement refers to the function draw as defined in class CIRCLE. EQU a.draw();
Whereas, the following statement refers to the function draw defined in class CIRCLE.sub.-- FILL. EQU b.draw();
Moreover, the following statements type cast object b to an object of type class CIRCLE and invoke the function draw that is defined in class CIRCLE.sub.-- FILL. ##STR4## Thus, the type casting preserves the call to the overriding function CIRCLE.sub.-- FILL::draw.
Although object-oriented techniques facilitate the development of complex computer programs, the resulting computer programs can be less efficient in execution speed and require more memory than a program developed without object-oriented techniques. It would be desirable to have method and system for implementing the techniques of object-oriented programming to improve the execution speed and reduce the memory requirements of the computer program.